/*
 * printer_bsp.h
 *
 *  Created on: Sep 25, 2023
 *      Author: EDY
 */

#pragma once
#ifdef __cplusplus
extern "C" {
#endif

#ifndef PRINTER_BSP_H_
#define PRINTER_BSP_H_

#define USE_NEW_REG_TABLE

#ifdef USE_OLD_REG_TABLE
#define SIZEOF_REG_TEST              1
#define SIZEOF_REG_BITSTREAMVER      1
#define SIZEOF_REG_POWERSTATUS       1
#define SIZEOF_REG_POWEREN           1
#define SIZEOF_REG_POWERDELAY1       1
#define SIZEOF_REG_POWERDELAY2       1
#define SIZEOF_REG_ID                1
#define SIZEOF_REG_PWRCTRL           1
#define SIZEOF_REG_CURPOSITON        2
#define SIZEOF_REG_TARGETPOSITON     2
#define SIZEOF_REG_PULSEWIDTH        2
#define SIZEOF_REG_PULSEWIDTHMIN     2
#define SIZEOF_REG_PULSEWIDTHMAX     2
#define SIZEOF_REG_PULSEMONITOREN    1
#define SIZEOF_REG_FIRINGTIME        1
#define SIZEOF_REG_DTIME             1
#define SIZEOF_REG_STIME             1
#define SIZEOF_REG_BUFFERPERCENT     1
#define SIZEOF_REG_SPITCONTROL       1
#define SIZEOF_REG_BUFFERTOTALSIZE   2
#define SIZEOF_REG_BUFFERUSEDSIZE    2
#define SIZEOF_REG_BUFFERRESET       1
#define SIZEOF_REG_SLICESTARTPOSITON 2
#define SIZEOF_REG_SLICEMODE         1
#define SIZEOF_REG_SLICEDIRECTION    1
#define SIZEOF_REG_DOTCOUNTCLR       1
#define SIZEOF_REG_INTERRUPTCLR      1
#define SIZEOF_REG_INTERRUPTSTATUS   1
#define SIZEOF_REG_FUNCTIONTEST      1
#define SIZEOF_REG_FIRETESTDATA      1
#define SIZEOF_REG_FIRELOOP          1
#define SIZEOF_REG_HTVPVLCECONTROL   1
#define SIZEOF_REG_ASDOUTCONTROL     2
#define SIZEOF_FPGA_SW_RST           1

#define ADD_REG_TEST              0x00
#define ADD_REG_BITSTREAMVER      0x01
#define ADD_REG_POWERSTATUS       0x02
#define ADD_REG_POWEREN           0x03
#define ADD_REG_POWERDELAY1       0x04
#define ADD_REG_POWERDELAY2       0x05
#define ADD_REG_ID                0x06
#define ADD_REG_PWRCTRL           0x07
#define ADD_REG_CURPOSITON        0x08
#define ADD_REG_TARGETPOSITON     0x0c
#define ADD_REG_PULSEWIDTH        0x10
#define ADD_REG_PULSEWIDTHMIN     0x12
#define ADD_REG_PULSEWIDTHMAX     0x14
#define ADD_REG_PULSEMONITOREN    0x16
#define ADD_REG_FIRINGTIME        0x17
#define ADD_REG_DTIME             0x18
#define ADD_REG_STIME             0x19
#define ADD_REG_BUFFERPERCENT     0x1a
#define ADD_REG_SPITCONTROL       0x1b
#define ADD_REG_BUFFERTOTALSIZE   0x1C
#define ADD_REG_BUFFERUSEDSIZE    0x1E
#define ADD_REG_BUFFERRESET       0x20
#define ADD_REG_SLICESTARTPOSITON 0x21
#define ADD_REG_SLICEMODE         0x25
#define ADD_REG_SLICEDIRECTION    0x26
#define ADD_REG_DOTCOUNTCLR       0x27
#define ADD_REG_INTERRUPTCLR      0x34
#define ADD_REG_INTERRUPTSTATUS   0x36
#define ADD_REG_FUNCTIONTEST      0x38
#define ADD_REG_FIRETESTDATA      0x39
#define ADD_REG_FIRELOOP          0x3A
#define ADD_REG_HTVPVLCECONTROL   0x3B
#define ADD_REG_ASDOUTCONTROL     0x3C
#define ADD_REG_FIREDATA          0x40
#define ADD_REG_FPGA_SW_RST       0x7F
#endif

#ifdef USE_NEW_REG_TABLE
#define SIZEOF_REG_TEST	1
#define SIZEOF_REG_BITSTREAMVER	1
#define SIZEOF_REG_PWRCTRL 1
#define SIZEOF_REG_FIRINGTIME	1
#define SIZEOF_REG_DTIME	1
#define SIZEOF_REG_STIME	1
#define SIZEOF_REG_WarmDHighTime 1
#define SIZEOF_REG_WarmDLowTime  1
#define SIZEOF_REG_WarmLoopCnt   1
#define SIZEOF_REG_FUNCTIONTEST	1
#define SIZEOF_REG_BUFFERAEMPTYSIZE 2
#define SIZEOF_REG_BUFFERTOTALSIZE	2
#define SIZEOF_REG_BUFFERUSEDSIZE	2
#define SIZEOF_REG_CURPOSITON	2
#define SIZEOF_REG_TARGETPOSITON	2
#define SIZEOF_REG_SLICESTARTPOSITON	2
#define SIZEOF_REG_SLICEMODE	1
#define SIZEOF_REG_INTERRUPTMASK	1
#define SIZEOF_REG_INTERRUPTSTATUS	1
#define SIZEOF_REG_HTVPVLCECONTROL 1
#define SIZEOF_REG_SOUTCONTROL 1
#define SIZEOF_REG_AOUTCONTROL 1
#define SIZEOF_REG_DOUTCONTROL 1
#define SIZEOF_REG_BUFFERRESET	1

//new regisiter table
#define ADD_REG_TEST	0x00
#define ADD_REG_BITSTREAMVER	0x01
#define ADD_REG_PWRCTRL 0x02
#define ADD_REG_FIRINGTIME	0x03
#define ADD_REG_DTIME	0x04
#define ADD_REG_STIME	0x05
#define ADDR_REG_WarmDHighTime 0x06
#define ADDR_REG_WarmDLowTime  0x07
#define ADDR_REG_WarmLoopCnt   0x08
#define ADD_REG_FUNCTIONTEST	0x09
#define ADD_REG_BUFFERAEMPTYSIZE 0x0A
#define ADD_REG_BUFFERTOTALSIZE	0x0C
#define ADD_REG_BUFFERUSEDSIZE	0x0E
#define ADD_REG_CURPOSITON	0x10
#define ADD_REG_TARGETPOSITON	0x12
#define ADD_REG_SLICESTARTPOSITON	0x14
#define ADD_REG_SLICEMODE	0x16
#define ADD_REG_INTERRUPTMASK	0x17
#define ADD_REG_INTERRUPTSTATUS	0x18
#define ADD_REG_HTVPVLCECONTROL 0x19
#define ADD_REG_SOUTCONTROL 0x1A
#define ADD_REG_AOUTCONTROL 0x1B
#define ADD_REG_DOUTCONTROL 0x1C
#define ADD_REG_BUFFERRESET	0x1F
#endif

void flash_test(uint16_t flash_cnt);
void nozzle_grid_test_pattern(uint8_t rpt_cnt);
void grid_test_pattern_gen(void);

void spicomm_task_init(void);
void FPGA_sw_reset(void);
int16_t get_curr_intstatus(void);
int16_t get_FPGA_version(void);
int16_t get_curr_position(void);
int16_t get_firefifo_buffer_total_size(void);
int16_t get_firefifo_used_buffer(void);
int16_t SPI_WRITE_FIREDATA(uint8_t *data);
void FPGA_read_test(void);
void FPGA_show_all_reg(void);
void fpga_start_fire_once(void);
int32_t drv_prn_testpattern(void);
void drv_prn_flashtest(uint16_t cnt);
void drv_mcu_sw_reset(void);
void drv_prn_self_test(void);
void FPGA_Buffer_reset(void);
void fpga_fireboard_power_up(void);
void fpga_fireboard_power_down(void);
int16_t fpga_get_pwr_status(void);
int32_t drv_prn_odd_even_offset_test();
int32_t drv_y_pattern_test(uint8_t pass_num);

#ifdef __cplusplus
}
#endif

#endif /* PRINTER_BSP_H_ */
